package com.zhan.signalling.check;

import java.util.Set;

import com.alibaba.fastjson.JSONObject;
import com.corundumstudio.socketio.SocketIOClient;
import com.zhan.signalling.commons.Constants;
import com.zhan.signalling.commons.SocketEvent;
import com.zhan.signalling.message.AccoutType;
import com.zhan.signalling.message.Result;
import com.zhan.signalling.server.SocketServer;

public class AccoutPermissionCheck {
	
		public static void check(SocketIOClient client, String event) {
			Integer accoutType = client.get(Constants.USER_TYPE);
			JSONObject user = client.get(Constants.USER_KEY);
			String token = client.get(Constants.USER_TOKEN);
			Set<Object> permission = SocketServer.permissionMap.get(AccoutType.getInstance(accoutType));
			if(!permission.contains(event)) {
				client.sendEvent(SocketEvent.EXCEPTION_EVENT, new Result("no permission : " + event, Constants.FAILED));
				throw new IllegalAccessError("client-token: "+ token +"user: " + user);
			}
		}
	
}
